var INI = function(path)
{
	this.path = path;
	
	this.read = function()
	{
		if (WshFSO.FileExists(this.path) && WshFSO.GetFile(this.path).Size > 0)
		{
			var file = WshFSO.OpenTextFile(this.path, 1, false, 0);
			this.content = file.ReadAll().replace(/\r\n/g, '\n');
			file.close();
		}
	}
	
	this.read();
	
	this.write = function()
	{
		if (WshFSO.FileExists(this.path) && WshFSO.GetFile(this.path).Size > 0)
		{
			var file = WshFSO.OpenTextFile(this.path + '.bak', 2, true, 0);
			file.write(this.content.replace(/\n/g, '\r\n'));
			file.close();
		}
	}
		
	this.getEntrySetting = function(entryName, settingName)
	{
		var strings = this.content.split('\n');
		var currentEntryName = '';
		var currentSettingName = '';
		var value = '';
		for (var i = 0; i < strings.length; i++)
		{
			if (strings[i].match(/^\[(.+)\]$/i))
			{
				currentEntryName = RegExp.$1;
			}
			
			if (strings[i].match(/^([^=]+)=(.*)$/i))
			{
				currentSettingName = RegExp.$1;
				value = RegExp.$2;
			}
			
			if (entryName === currentEntryName && settingName === currentSettingName)
			{
				return(value);
			}
		}
		
		return(null);
	}
	
	this.setEntrySetting = function(entryName, settingName, value)
	{
		if (this.getEntrySetting(entryName, settingName) === null)
		{
			this.content = this.content.replace(new RegExp('(\\[' + entryName + '\\])([\\n]+)'), function($0, $1, $2) { return($1 + $2 + settingName + '=' + value + $2); });
		}
		else
		{
			this.content = this.content.replace(new RegExp('(\\[' + entryName + '\\])((?:.|[\\n])+?' + settingName + '=).*'), function($0, $1, $2) { return($1 + $2 + value); });
		}
	}
	
	return(this);
}
